package Common;

//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
	///#region  �ļ������ݿ�ͨ�õĲ���

/** 
 �ļ������ݿ�ͨ�õĲ���
*/
public abstract class CommonFileDBC
{

	/** 
	 �õ����� Excel ���ݿ�����Ӵ�
	 
	 @param XlsFile
	 @return 
	*/
	public static String GetXlsConnStr(String XlsFile)
	{
		return "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + XlsFile + ";" + "Extended Properties=Excel 8.0;";
	}

	/** 
	 �õ����ļ����ݿ����Ӻ�����ݼ�
	 
	 @param FileDBCConnString �����ִ�
	 @return �õ� Sheet1 ����������
	*/
	public static DataSet CreateDataSet(String FileDBCConnString)
	{
		try
		{
			OleDbConnection conn = new OleDbConnection(FileDBCConnString);
			OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", conn);
			DataSet myDataSet = new DataSet();
			myCommand.Fill(myDataSet);

			return myDataSet;
		}
		catch (java.lang.Exception e)
		{
			// can not connect to Xls file or get data failed;
			return null;
		}
	}


	/** 
	 �õ����ļ����ݿ����Ӻ�����ݼ�ָ����Ԫҳ������
	 
	 @param FileDBCConnString ���Ӵ�
	 @param SheetName Sheet ��
	 @return 
	*/
	public static DataSet CreateDataSet(String FileDBCConnString, String SheetNameOrSqlStr)
	{
		try
		{
			OleDbConnection conn = new OleDbConnection(FileDBCConnString);
			String strSql = "";
			if ((SheetNameOrSqlStr == null) || (SheetNameOrSqlStr.equals("")))
			{
				strSql = "SELECT * FROM [Sheet1$]";
			}
			else
			{
				//��������Sql ��仹�� sheet ��������û�� Select  ��ͷΪ׼��
				if (SheetNameOrSqlStr.trim().substring(0,7).toUpperCase().equals("SELECT "))
				{
					strSql = SheetNameOrSqlStr;
				}
				else
				{
					strSql = String.format("SELECT * FROM [%1$s$]",SheetNameOrSqlStr);
				}
			}

			OleDbDataAdapter myCommand = new OleDbDataAdapter(strSql, conn);
			DataSet myDataSet = new DataSet();
			myCommand.Fill(myDataSet);

			return myDataSet;
		}
		catch (java.lang.Exception e)
		{
			// can not connect to Xls file or get data failed;
			return null;
		}
	}

}